package db

import (
	"go.mongodb.org/mongo-driver/bson"
	persis "my-gameserver-go/logic/persistenceObj"
	"reflect"
)

var UserAccess *UserDBAccess

type UserDBAccess struct {
	DBConn *MongoDbConn
}

func (u *UserDBAccess) findById(pojoId int64, objType reflect.Type) any {
	return nil
}

func (u *UserDBAccess) Save(saveObj BaseSaveObj) bool {
	return u.DBConn.Save(saveObj)
}

func (u *UserDBAccess) FindUserByUserName(userName string) *persis.User {
	user := &persis.User{}
	success := u.DBConn.FindOne(bson.M{"username": userName}, user)
	if success {
		return user
	}
	return nil
}

func (u *UserDBAccess) HasUser(userName string) (bool, error) {
	user := &persis.User{}
	return u.DBConn.HasObj(bson.M{"username": userName}, user)
}
